package com.landcode.common.config.exception;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class ExceptionConfig {

    @Pointcut("execution(public * com.landcode..*.*(..))")
    public void pcMethod() {

    }

    @AfterThrowing(pointcut = "pcMethod()", throwing = "e")
    public void doException(JoinPoint jp, Throwable e) {
        if (e != null) {
            StackTraceElement[] arr = e.getStackTrace();
            for (int i = 0; i < arr.length; i++) {
                log.error(arr[i].toString());
            }
        }
    }
}
